package com.ls.code01;

import java.util.LinkedList;

/**
 * @author LS
 * @version 1.0
 * @description: 快速排序
 * @date 2021/5/3 下午1:23
 */
public class Code04 {

    public static void print(int[] arr) {
        //0～0 完成
        //0～1
        //0～2
        for (int end = 1; end < arr.length; end++) {
            int maxValueIndex = end;
            while (maxValueIndex - 1 >= 0 && arr[maxValueIndex] < arr[maxValueIndex - 1]) {
                swap(arr, maxValueIndex, maxValueIndex -1);
                maxValueIndex --;
            }
        }
    }

    public static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 1, 4, 3, 2, 8, 5, 2};
        print(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }

        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("123");
        linkedList.add("134");
        linkedList.add("egr");
        System.out.println(linkedList);
    }

}
